package com.wswy.wzcx.ui.main.community

import com.che.libcommon.api.BaseResult
import com.che.libcommon.api.SimpleResultObserver
import com.che.libcommon.api.VoidResultObserver
import com.wswy.wzcx.AppContext
import com.wswy.wzcx.api.Api
import com.wswy.wzcx.model.topic.CommentModel
import com.wswy.wzcx.statistics.StatTools
import com.wswy.wzcx.statistics.StatisticsId

data class CommentVO(val model:CommentModel,
                     val date:CharSequence?=null,
                     var like:Int=0,
                     var liked: Boolean = false):InteractiveVO {

    override fun getLikeCount(): Int = like

    override fun getReviewCount(): Int = 0

    override fun isLiked(): Boolean = liked

    override fun addLike(send: Boolean) {

        if (!liked) Api.get().commentAddLike(model.id).subscribe(object :SimpleResultObserver(){
            override fun onSuccess() {

                StatTools.sendClick(AppContext.getContext(),StatisticsId.bbs_detail_comment_like)

            }

            override fun onApiError(result: BaseResult<*>?) {
                toastErrorMsg(result)
            }

        })
        like++
        liked = true

    }

    override fun removeLike() {

        like--
        liked = false

    }

}